<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // 用户登录日志
        Schema::create('login_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->nullable()->comment('User ID');
            $table->string('name', 255)->comment('登录账号');

            $table->boolean('status')->default(false)->comment('是否登录成功');
            $table->string('message', 255)->nullable()->comment('登录消息');
            $table->string('login_ip', 45)->nullable()->comment('登录IP');
            $table->timestamp('login_at')->nullable()->comment('登录时间');

            $table->text('user_agent')->nullable()->comment('请求头');
            $table->string('referer', 255)->nullable()->comment('来源页面');

            $table->string('device', 255)->nullable()->comment('设备');
            $table->string('browser', 255)->nullable()->comment('浏览器');
            $table->string('os', 255)->nullable()->comment('操作系统');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('login_logs');
    }
};
